<?php
/**
 * 会员短消息管理
 *
 * @version        $Id: member_pm.php 1 11:24 2010年7月20日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");
CheckPurview('member_Pm');
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");
require_once(DEDEINC .'/datalistcp.class.php');

if(!isset($folder)) $folder = '';
if(!isset($username)) $username = '';
if(!isset($keyword)) $keyword = '';

if(isset($dopost))
{
    $ID = preg_replace("#[^0-9]#", "", $ID);
	$txid = preg_replace("#[^0-9]#", "", $txid);
    if($dopost=="del"&&!empty($ID))
    {
        $dsql->ExecuteNoneQuery("DELETE FROM #@__member_pms WHERE id='$ID'");
    }
	else if($dopost=='txcl'&&!empty($txid))//提现处理成功
	{
		$query = "Update `#@__member_pms` set txcl='1' WHERE txid='$txid';";
		$dsql->ExecuteNoneQuery($query);
		
		$query = "Update `#@__member_operation` set sta='2' WHERE txid='$txid';";
		$dsql->ExecuteNoneQuery($query);
		//ShowMsg("处理成功!","pm.php",0,8);
		header("Location: member_tx.php");
		exit();
	}
	else if($dopost=='shibai'&&!empty($txid))//提现处理失败
	{
		$query = "Update `#@__member_pms` set txcl='2' WHERE txid='$txid';";
		$dsql->ExecuteNoneQuery($query);
		
		$query = "Update `#@__member_operation` set sta='6' WHERE txid='$txid';";
		$dsql->ExecuteNoneQuery($query);
		//ShowMsg("处理成功!","pm.php",0,8);
		header("Location: member_tx.php");
		exit();
	}
	
	
}

$whereSql = '';


if(!empty($keyword))
{
    $whereSql .= " AND (b.buyid ='".$keyword."')";
}
if(!empty($username))
{
    $whereSql .= " AND ( a.floginid like '%".$username."%')";
}
$sql = "SELECT * FROM #@__member_pms a,#@__member_operation b where a.txid=b.aid  $whereSql ORDER BY a.sendtime desc";
$dlist = new DataListCP();
$dlist->pagesize = 25;
$dlist->SetParameter("folder",$folder);
$dlist->SetParameter("username",$username);
$dlist->SetParameter("keyword",$keyword);
$dlist->SetTemplate(DEDEADMIN."/templets/member_tx.htm");
$dlist->SetSource($sql);
$dlist->Display();
$dlist->Close();


function IsReader($me)
{
    $me = preg_replace("#[^0-1]#", "", $me);
    if($me) return "<font color='green'>√</font>";
    else return "<font color='red'>×</font>";
}

function State($me)
{
    $me = preg_replace("#[^0-2]#", "", $me);
    if($me==1){
		return "<font color='green'>提现成功</font>";
	}else if($me==2){
		return "<font color='red'>失败</font>";
	}else{
		 return "<font color='blue'>未处理</font>";
	}
		
	
    
}
